home *** CD-ROM | disk | FTP | other *** search
- Path: atglab.bls.com!Alun.Champion
- From: Alun.Champion@bridge.bst.bls.com (Alun Champion)
- Newsgroups: comp.lang.c++
- Subject: Re: Parameterless functions
- Date: 19 Jan 1996 22:22:09 GMT
- Organization: Computer People Inc.
- Message-ID: <ALUN.CHAMPION.96Jan19172209@g7240065.bridge.bst.bls.com>
- References: <9601191115.aa06760@paris.ics.uci.edu>
- NNTP-Posting-Host: bstfirewall.bst.bls.com
- In-reply-to: klefstad@catalina.ICS.UCI.EDU's message of 19 Jan 96 19:18:31 GMT
-
- In article <9601191115.aa06760@paris.ics.uci.edu> klefstad@catalina.ICS.UCI.EDU ("Raymond Klefstad, Ph.D.") writes:
-
- : Why does the following function work? Is this just gcc or is it correct
- : C++? endl and ends are implemented this way.
-
- : #include <iostream.h>
-
- : ostream& newline(ostream& out)
- : {
- : return out << "Hello";
- : }
-
- : main()
- : {
- : cout << "Hello" << newline;
- : }
-
- This works because the ostream has an operator << defined that
- takes a function of the type above and all it does is call the function
- with itself as the argument i.e:
-
- ostream& operator << (ostream& (*)(ostream&)
- { return (*f)(*this); }
-
- Though the (*f) can be replaces with just f:
-
- ostream& operator << (ostream& (*)(ostream&)
- { return f(*this); }
-
- : Also, I noticed the following in some of the standard headers for gcc:
-
- : int foo(int x) return y
- : {
- : y = 10;
- : // do stuff and drop of the end of the function, but y is returned
- : // similar to Pascal. Is this valid C++ or just GNU extensions.
- : }
-
- Not any valid C++ I have seen before.
-
- Regards
-
- -A.
- --
- | A.Champion |
-